cssstyle: Add gtk_css_style_is_static()
authorBenjamin Otte <otte@redhat.com>
Fri, 27 Feb 2015 17:41:13 +0000 (18:41 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 Mar 2015 14:23:33 +0000 (15:23 +0100)
Gets rid of the need to do

  if (ANIMATED_STYLE() &&
      animated_style_is_static(ANIMATED_STYLE(style))

gtk/gtkcssanimatedstyle.c
gtk/gtkcssanimatedstyleprivate.h
gtk/gtkcssnode.c
gtk/gtkcssstyle.c
gtk/gtkcssstyleprivate.h

index 6e845f689eb87edfecf9b7eb43fe7f4ed261582e..d13403aaa88ab602479bc0343e1d9f8a9bdda9b1 100644 (file)
@@ -63,6 +63,21 @@ gtk_css_animated_style_get_section (GtkCssStyle *style,
   return gtk_css_style_get_section (animated->style, id);
 }
 
+static gboolean
+gtk_css_animated_style_is_static (GtkCssStyle *style)
+{
+  GtkCssAnimatedStyle *animated = GTK_CSS_ANIMATED_STYLE (style);
+  GSList *list;
+
+  for (list = animated->animations; list; list = list->next)
+    {
+      if (!_gtk_style_animation_is_static (list->data, animated->current_time))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 static void
 gtk_css_animated_style_dispose (GObject *object)
 {
@@ -101,6 +116,7 @@ gtk_css_animated_style_class_init (GtkCssAnimatedStyleClass *klass)
 
   style_class->get_value = gtk_css_animated_style_get_value;
   style_class->get_section = gtk_css_animated_style_get_section;
+  style_class->is_static = gtk_css_animated_style_is_static;
 }
 
 static void
@@ -472,19 +488,3 @@ gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
 
   return GTK_CSS_STYLE (result);
 }
-
-gboolean
-gtk_css_animated_style_is_static (GtkCssAnimatedStyle *style)
-{
-  GSList *list;
-
-  gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), TRUE);
-
-  for (list = style->animations; list; list = list->next)
-    {
-      if (!_gtk_style_animation_is_static (list->data, style->current_time))
-        return FALSE;
-    }
-
-  return TRUE;
-}
index 4a6d2b975a727176dae7e073d598d71fb427a223..7ae8887eeba5cec14ac05dcad8597a8226820e61 100644 (file)
@@ -68,8 +68,6 @@ void                    gtk_css_animated_style_set_animated_value(GtkCssAnimated
 GtkCssValue *           gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
                                                                  guint                   id);
 
-gboolean                gtk_css_animated_style_is_static        (GtkCssAnimatedStyle    *style);
-
 G_END_DECLS
 
 #endif /* __GTK_CSS_ANIMATED_STYLE_PRIVATE_H__ */
index 11200d84ef9ede11ec8adebbebd738473120f09b..297068b4862aa194d07ebf2904994ac092a10bfe 100644 (file)
@@ -271,8 +271,7 @@ gtk_css_node_real_update_style (GtkCssNode   *cssnode,
       new_style = g_object_ref (style);
     }
 
-  if (GTK_IS_CSS_ANIMATED_STYLE (new_style) &&
-      !gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (new_style)))
+  if (!gtk_css_style_is_static (new_style))
     gtk_css_node_set_invalid (cssnode, TRUE);
 
   g_object_unref (new_static_style);
@@ -901,8 +900,7 @@ gtk_css_node_validate_internal (GtkCssNode *cssnode,
 
   /* need to set to FALSE then to TRUE here to make it chain up */
   gtk_css_node_set_invalid (cssnode, FALSE);
-  if (GTK_IS_CSS_ANIMATED_STYLE (cssnode->style) &&
-      !gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (cssnode->style)))
+  if (!gtk_css_style_is_static (cssnode->style))
     gtk_css_node_set_invalid (cssnode, TRUE);
 
   GTK_CSS_NODE_GET_CLASS (cssnode)->validate (cssnode);
index 084919159ec6468f8d90549904d75d989e20f71b..c4afe134686faf14854437dcdfd951ca8f5b076d 100644 (file)
@@ -46,10 +46,17 @@ gtk_css_style_real_get_section (GtkCssStyle *style,
   return NULL;
 }
 
+static gboolean
+gtk_css_style_real_is_static (GtkCssStyle *style)
+{
+  return TRUE;
+}
+
 static void
 gtk_css_style_class_init (GtkCssStyleClass *klass)
 {
   klass->get_section = gtk_css_style_real_get_section;
+  klass->is_static = gtk_css_style_real_is_static;
 }
 
 static void
@@ -97,6 +104,15 @@ gtk_css_style_get_difference (GtkCssStyle *style,
   return result;
 }
 
+gboolean
+gtk_css_style_is_static (GtkCssStyle *style)
+{
+  gtk_internal_return_val_if_fail (GTK_IS_CSS_STYLE (style), TRUE);
+
+  return GTK_CSS_STYLE_GET_CLASS (style)->is_static (style);
+}
+
+
 void
 gtk_css_style_print (GtkCssStyle *style,
                      GString     *string)
index ad5b596b6ff18d6951f26d70a1f70f7df7b1a307..d3226a635a1ea60e10b7cef54a6fbb682957f828 100644 (file)
@@ -54,6 +54,8 @@ struct _GtkCssStyleClass
    * Optional: default impl will just return NULL */
   GtkCssSection *       (* get_section)                         (GtkCssStyle            *style,
                                                                  guint                   id);
+  /* TRUE if this style will require changes based on timestamp */
+  gboolean              (* is_static)                           (GtkCssStyle            *style);
 };
 
 GType                   gtk_css_style_get_type                  (void) G_GNUC_CONST;
@@ -64,6 +66,7 @@ GtkCssSection *         gtk_css_style_get_section               (GtkCssStyle
                                                                  guint                   id);
 GtkBitmask *            gtk_css_style_get_difference            (GtkCssStyle            *style,
                                                                  GtkCssStyle            *other);
+gboolean                gtk_css_style_is_static                 (GtkCssStyle            *style);
 
 char *                  gtk_css_style_to_string                 (GtkCssStyle            *style);
 void                    gtk_css_style_print                     (GtkCssStyle            *style,